/*
 * @Author: your name
 * @Date: 2021-08-31 14:37:34
 * @LastEditTime: 2021-09-27 00:13:26
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \egg-example\app\controller\home.js
 */
'use strict';
const Controller = require('egg').Controller;
const path = require('path')
const pump = require('pump')
const fs = require('fs')
class HomeController extends Controller {
  //==================测试页面=========================
  async index() {
    const { ctx } = this;
    ctx.body = '接口可以用啦';
  }
  //==================登录注册============================
  //注册
  async register() {
    const { ctx } = this;
    const { username, password, nickname } = ctx.query;
    const post = await this.app.mysql.get('login', { username: username });
    if (post) {
      ctx.body = {
        code: 500,
        msg: "注册失败，账户已经存在",
      };

    } else {
      const result = await this.app.mysql.insert('login', { username: username, password: password, nickname: nickname });
      ctx.body = {
        code: 200,
        msg: "注册成功",
        data: result
      };
    }
  }
  //登录
  async login() {
    const { ctx, app } = this;
    // post请求传来的参数
    const { username } = ctx.query;
    // 判断数据库里面是否存在该用户
    const user = await this.app.mysql.get('login', { username });

    if (user.lls === "true") {
      if (user) {
        // 用户存在,生成token
        const token = app.jwt.sign({
          name: user.username,
        }, app.config.jwt.secret);
        ctx.body = {
          code: 200,
          message: '登录成功',
          data: user,
          token
        }
      } else {
        ctx.body = {
          code: 500,
          message: '登录失败',
        }
      }
    } else {
      ctx.body = {
        code: 500,
        message: '暂无权限，禁止登录',
      }
    }
  }

  async loginquan() {
    const { ctx } = this;
    const { id, username, password, nickname, lls, title } = ctx.query
    console.log(id, "id", username, "username", password, "password", nickname, "nickname", lls, "lls", title, "title", "博");
    if (id) {
      const post = await this.app.mysql.get('login', { id: id })
      if (post.username === "admin") {
        ctx.body = {
          code: 200,
          msg: "删除失败,超级管理员禁止删除",
        }
      } else {
        const result = await this.app.mysql.delete('login', { id: id });
        if (result.affectedRows === 1) {
          ctx.body = {
            code: 200,
            msg: "删除成功",
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "删除失败",
          }
        }
      }

    } else if (username && password && nickname && lls && title) {
      console.log("添加");
      const post = await this.app.mysql.get('login', { username });
      console.log(post, "post");
      if (post) {
        ctx.body = {
          code: 200,
          msg: "账户已经存在，编辑失败",
        }
      } else {
        const result = await this.app.mysql.insert('login', { username: username, password: password, nickname: nickname, lls: lls, title: title })
        if (result.affectedRows === 1) {
          ctx.body = {
            code: 200,
            msg: "添加成功",
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "添加失败",
          }
        }
      }

    } else {
      const results = await this.app.mysql.select('login');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    }
  }

  async loginquans() {
    const { ctx } = this;
    const { id, username, password, lls, nickname, title } = ctx.query
    console.log(id, username, password, lls, nickname, title, "798546");
    const results = await this.app.mysql.get('login', { id });
    const result = await this.app.mysql.update('login', { id: id, username: username, password: password, nickname: nickname, lls: lls, title: title });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "编辑成功",
      }
    } else {
      ctx.body = {

        code: 500,
        msg: "编辑失败",
      }
    }
  }


  //==================管理页面啥=========================
  async Productdata() {
    const { ctx } = this;
    const { pindex, psize, classify, search } = ctx.query;
    if (pindex && psize) {
      const sql = `SELECT * FROM productdata limit ${pindex},${psize}`
      const data = await this.app.mysql.query(sql)
      const results = await this.app.mysql.select('productdata');
      ctx.body = {
        code: 200,
        msg: "分页数据请求成功",
        data: data,
        total: results.length
      };
    } else if (classify) {

    } else {
      const sql = `SELECT * FROM productdata where name like'%${search}%'`
      const data = await this.app.mysql.query(sql)
      if (data.length === 0) {
        ctx.body = {
          code: 200,
          msg: "数据不存在",
        };
      } else {
        ctx.body = {
          code: 200,
          msg: "搜索成功",
          data: data,
        };
      }

    }

  }
  //编辑
  async Productupdata() {
    const { ctx } = this;
    const { id, img, name, price, salesvolume, repertory, sort, sate, time, type} = ctx.query;
    console.log(id, img, name, price, salesvolume, repertory, sort, sate, time, type);
    const sql = `UPDATE productdata SET img=${img} name=${name} price=${price} salesvolume=${salesvolume} repertory=${repertory} sort=${sort} sate=${sate} time=${time} type=${type} where id=${id}`
    const data = await this.app.mysql.query(sql)
    ctx.body = {
      data
    }
  }
  //删除
  async Productdetile() {
    const { ctx } = this;
    const { id } = ctx.query;
    console.log(id);
    const result = await this.app.mysql.delete('productdata', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
        result
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }

  //===============商品分类================


  async classify() {
    const { ctx } = this;
    const results = await this.app.mysql.select('classify');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //编辑
  async classifyupdata() {
    const { ctx } = this; const { id, type, img, sort, state, name, lls } = ctx.query
    await this.app.mysql.update('classify', { id, type, img, sort, state, name, lls });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "编辑成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "编辑失败",
      }
    }
  }
  //分类模糊搜索
  async classifysearch() {
    const { ctx } = this;
    const { name, sou } = ctx.query;
    if (sou === "全部") {
      const { ctx } = this;
      const results = await this.app.mysql.select('classify');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (name) {
        const sql = `SELECT * FROM classify where name like'%${name}%'`
        const data = await this.app.mysql.query(sql)
        console.log(sou, "sou", name, "name", "大弟");
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      } else if (sou) {
        const sql = `SELECT * FROM classify where lls like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        console.log(sou, "sou", name, "name", "大弟");
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }


  }
  //删除
  async classdetile() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('classify', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }

  //===============商品规格啥================
  async guige() {
    const { ctx } = this;
    const results = await this.app.mysql.select('guige');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //模糊搜索
  async guigesearch() {
    const { ctx } = this;
    const { name } = ctx.query;
    const sql = `SELECT * FROM guige where name like'%${name}%'`
    const data = await this.app.mysql.query(sql)
    if (data.length > 0) {
      ctx.body = {
        code: 200,
        msg: "搜索成功",
        data: data
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "暂无数据",
      }
    }

  }
  //删除
  async guigdetile() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('guige', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }

  async alldleat() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const sql = `delete from guige`
    const result = this.app.mysql.query(sql)
    if (result) {
      ctx.body = {
        code: 500,
        msg: "删除失败",
        result
      }
    } else {

    } ctx.body = {
      code: 200,
      msg: "删除成功",
    }
  }

  //===============商品评价================
  async evaluation() {
    const { ctx } = this;
    const results = await this.app.mysql.select('pinjia');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //模糊搜索
  async evalusearch() {
    const { ctx } = this;
    const { name } = ctx.query;
    const sql = `SELECT * FROM pinjia where name like'%${name}%'`
    const data = await this.app.mysql.query(sql)
    if (data.length > 0) {
      ctx.body = {
        code: 200,
        msg: "搜索成功",
        data: data
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "暂无数据",
      }
    }

  }
  //删除
  async evaludetile() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('pinjia', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //===============秒杀管理======
  //秒杀配置
  async Seconds() {
    const { ctx } = this;
    const results = await this.app.mysql.select('miaopei');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //编辑
  async Secondss() {
    const { ctx } = this;
    const { id, name, mtime, img, zhuangt, ctime } = ctx.query
    console.log(id, name, mtime, img, zhuangt, ctime, "大壮");
    if (id && name && mtime && img && zhuangt && ctime) {
      const result = await this.app.mysql.update('miaopei', { id: id, name: name, mtime: mtime, img: img, zhuangt: zhuangt, ctime: ctime });
      if (result.affectedRows === 1) {
        ctx.body = {
          code: 200,
          msg: "编辑成功",
        }
      } else {
        ctx.body = {
          code: 500,
          msg: "编辑失败",
        }
      }
    } else {
      console.log(name, mtime, img, zhuangt, ctime);
      const result = await this.app.mysql.insert('miaopei', { name: name, mtime: mtime, img: img, zhuangt: zhuangt, ctime: ctime })
      if (result.affectedRows === 1) {
        ctx.body = {
          code: 200,
          msg: "添加成功",
        }
      } else {
        ctx.body = {
          code: 500,
          msg: "添加失败",
        }
      }
    }
  }

  // id  name		mtime	img		zhuangt	ctime
  //模糊搜索
  async Secondssearch() {
    const { ctx } = this;
    const { name, sou } = ctx.query;
    console.log(name, "name", sou, "sou", "大壮");
    if (sou === "请选择") {
      const results = await this.app.mysql.select('miaopei');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (name) {
        // console.log(name,"“namsssssss");
        const sql = `SELECT * FROM miaopei where name like'%${name}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      } else if (sou) {
        // console.log(sou);
        const sql = `SELECT * FROM miaopei where zhuangt like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功jins",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }

  }
  //删除
  async Secondsdetile() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('miaopei', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //````````````````````````````````````````````
  //秒杀商品
  async Secondskill() {
    const { ctx } = this;
    const results = await this.app.mysql.select('miaoshop');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }


  // id,peizhi,mtime,img,title,huojian,yjia,mjia,xianl,xianls,mzhuang,zhuang,time
  //编辑
  async Secondsupdata() {
    const { id, peizhi, mtime, img, title, huojian, yjia, mjia, xianl, xianls, mzhuang, zhuang, time } = ctx.query
    const result = await this.app.mysql.update('miaoshop', { id, peizhi, mtime, img, title, huojian, yjia, mjia, xianl, xianls, mzhuang, zhuang, time })
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "添加成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "添加失败",
      }
    }
  }
  //模糊搜索
  async Seckillsearch() {
    const { ctx } = this;
    const { peizhi, sou } = ctx.query;
    console.log(peizhi, "name", sou, "sou", "大壮");
    if (sou === "请选择") {
      const results = await this.app.mysql.select('miaoshop');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (peizhi) {
        // console.log(name,"“namsssssss");
        const sql = `SELECT * FROM miaoshop where mzhuang like'%${peizhi}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      } else if (sou) {
        console.log(sou, "sousousoosu");
        const sql = `SELECT * FROM miaoshop where mzhuang like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功jins",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }




  }
  //删除
  async Seckilldetile() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('miaoshop', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //===============砍价管理======
  //秒砍价商品
  async bargain() {
    const { ctx } = this;
    const results = await this.app.mysql.select('kanshop');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //	id,img,kjia,zuijia,ren,	bang,cheng,xianl,xianls,time,zhuang,name,zhuangs
  async bargainbian() {
    const { ctx } = this
    const { id, img, kjia, zuijia, ren, bang, cheng, xianl, xianls, time, zhuang, name, zhuangs } = ctx.query
    console.log(id, img, kjia, zuijia, ren, bang, cheng, xianl, xianls, time, zhuang, name, zhuangs, "刘倩");
    const result = await this.app.mysql.update('kanshop', { id, img, kjia, zuijia, ren, bang, cheng, xianl, xianls, time, zhuang, name, zhuangs })
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "添加成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "添加失败",
      }
    }
  }
  //砍价删除
  async bargaindleat() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('kanshop', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //砍价搜索筛选
  async bargainsous() {
    const { ctx } = this;
    const { name, sou } = ctx.query;
    console.log(name, "name", sou, "sou", "刘倩");
    if (sou === "请选择") {
      const results = await this.app.mysql.select('kanshop');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (name) {
        // console.log(name,"“namsssssss");
        const sql = `SELECT * FROM kanshop where name like'%${name}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功name",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无直播",
          }
        }
      } else if (sou) {
        console.log(sou);
        const sql = `SELECT * FROM kanshop where zhuangs like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功jins",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }
  }
  //加
  async liveupdata() {
    const { ctx } = this; const { img, zhong, name, jin, lls, title, time } = ctx.query
    console.log(img, zhong, name, jin, lls, title, time, "大黄");
    const data = await this.app.mysql.insert('bolist', { img: img, zhong: zhong, name: name, jin: jin, lls: lls, title: title, time: time });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "编辑成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "编辑失败",
      }
    }
  }
  //秒砍价列表
  async bargainkill() {
    const { ctx } = this;
    const results = await this.app.mysql.select('kanlist');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }

  //删除
  async bargainkilldleat() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('kanlist', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //筛选
  async bargainkillsous() {
    const { ctx } = this;
    const { sou } = ctx.query;
    if (sou === "请选择") {
      const results = await this.app.mysql.select('kanlist');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      console.log(sou, "刘倩bargainkillsous");
      const sql = `SELECT * FROM kanlist where zhuang like'%${sou}%'`
      const data = await this.app.mysql.query(sql)
      // console.log(data);
      if (data.length > 0) {
        ctx.body = {
          code: 200,
          msg: "搜索成功jins",
          data: data
        }
      } else {
        ctx.body = {
          code: 500,
          msg: "暂无数据",
        }
      }
    }
  }
  //===============直播管理======
  //直播商品
  async live() {
    const { ctx } = this;
    const results = await this.app.mysql.select('bolist');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //直播删除
  async livedleat() {
    const { ctx } = this;
    const { id } = ctx.query;
    // console.log(id);
    const result = await this.app.mysql.delete('bolist', {
      id: id
    });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //直播分页
  async livedata() {
    const { ctx } = this;
    const { pindex, psize } = ctx.query;
    if (pindex || psize) {
      const sql = `SELECT * FROM bolist limit ${(pindex - 1) * psize},${psize}`
      const data = await this.app.mysql.query(sql)
      const results = await this.app.mysql.select('bolist');
      ctx.body = {
        code: 200,
        msg: "分页数据请求成功",
        data: data,
        total: results.length
      };
    } else {
      const { ctx } = this;
      const results = await this.app.mysql.select('bolist');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    }

  }

  //直播搜索、
  async livesou() {
    const { ctx } = this;
    const { name, sou } = ctx.query;
    if (sou === "全部" || sou === "") {
      const sql = `SELECT * FROM bolist limit ${(1 - 1) * 10},${10}`
      const data = await this.app.mysql.query(sql)
      const results = await this.app.mysql.select('bolist');
      ctx.body = {
        code: 200,
        msg: "分页数据请求成功",
        data: data,
        total: results.length
      };
    } else {
      if (name === "" || name) {
        if (name === "") {
          const sql = `SELECT * FROM bolist limit ${(1 - 1) * 10},${10}`
          const data = await this.app.mysql.query(sql)
          const results = await this.app.mysql.select('bolist');
          ctx.body = {
            code: 200,
            msg: "分页数据请求成功",
            data: data,
            total: results.length
          };
        } else {
          const sql = `SELECT * FROM bolist where name like'%${name}%'`
          const data = await this.app.mysql.query(sql)
          if (data.length > 0) {
            ctx.body = {
              code: 200,
              msg: "搜索成功name",
              data: data
            }
          } else {
            ctx.body = {
              code: 500,
              msg: "暂无直播",
            }
          }
        }

      } else if (sou) {
        const sql = `SELECT * FROM bolist where jin like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功",
            data: data,
            total: data.length
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }
  }
  //===============拼团管理======
  //拼团商品
  async grouppurchase() {
    const { ctx } = this;
    const results = await this.app.mysql.select('pinshop');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  async grouppurupdata() {
    const { ctx } = this;
    const { tuan, shangid, img, shangjie, yjia, pjia, chenren, canren, time, lls, huoz, llss } = ctx.query
    const result = await this.app.mysql.insert('posts', { tuan, shangid, img, shangjie, yjia, pjia, chenren, canren, time, lls, huoz, llss });
    if (result.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "添加成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "添加失败",
      }
    }
  }
  async grouppurchasesou() {
    const { ctx } = this;
    const { name, sou } = ctx.query;
    console.log(sou, "搜素");
    if (sou === "请选择" || sou === "") {
      const results = await this.app.mysql.select('pinshop');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (name) {
        const sql = `SELECT * FROM pinshop where tuan like'%${name}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功name",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无直播",
          }
        }
      } else if (sou) {
        const sql = `SELECT * FROM pinshop where llss like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功jins",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }
  }
  async BookListEdit() {
    const { ctx } = this;
    const { id, tuan, yjia, pjia, chenren, time, huoz } = ctx.request.body
    console.log(id, tuan, yjia, pjia, chenren, time, huoz, "加");
    const data = await this.app.mysql.update('pinshop', { id, tuan, yjia, pjia, chenren, time, huoz });
    ctx.body = {
      data
    }
  }

  //拼团列表
  async grouppurchaselist() {
    const { ctx } = this;
    const results = await this.app.mysql.select('pinlist');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //拼团商品删除
  async grouppurchaseDel() {
    const { ctx } = this;
    const { id } = ctx.query
    const data = await this.app.mysql.delete('pinshop', {
      id: id,
    });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //拼团列表删除
  async grouppurchaselistDel() {
    const { ctx } = this;
    const { id } = ctx.query
    const data = await this.app.mysql.delete('pinlist', {
      id: id,
    });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }

  //拼团列表搜索
  async grouppurchaselistshai() {
    const { ctx } = this;
    const { sou } = ctx.query;
    if (sou === "请选择" || sou === "") {
      const results = await this.app.mysql.select('pinlist');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      const sql = `SELECT * FROM pinlist where lls like'%${sou}%'`
      const data = await this.app.mysql.query(sql)
      if (data.length > 0) {
        ctx.body = {
          code: 200,
          msg: "搜索成功jins",
          data: data
        }
      } else {
        ctx.body = {
          code: 500,
          msg: "暂无数据",
        }
      }
    }
  }

  //===============订单管理======
  //订单管理
  async orderform() {
    const { ctx } = this;
    const { pindex, psize } = ctx.query;
    if (pindex || psize) {
      const sql = `SELECT * FROM dinguan limit ${(pindex - 1) * psize},${psize}`
      const data = await this.app.mysql.query(sql)
      const results = await this.app.mysql.select('dinguan');
      ctx.body = {
        code: 200,
        msg: "分页数据请求成功",
        data: data,
        total: results.length
      };
    } else {
      const { ctx } = this;
      const results = await this.app.mysql.select('dinguan');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    }
  }
  //订单管理搜索
  async orderformdata() {
    const { ctx } = this;
    const { name, id } = ctx.query;
    console.log(name, "name", id, "id", "刘仁兴");
    if (name = "" || name) {
      const sql = `SELECT * FROM dinguan where name like'%${name}%'`
      const data = await this.app.mysql.query(sql)
      if (data.length > 0) {
        ctx.body = {
          code: 200,
          msg: "搜索成功",
          data: data
        }
      } else {
        ctx.body = {
          code: 500,
          msg: "暂无数据",
          data: []
        }
      }
    } else {
      const sql = `SELECT * FROM dinguan where id like'%${id}%'`
      const data = await this.app.mysql.query(sql)
      if (data.length > 0) {
        ctx.body = {
          code: 200,
          msg: "搜索成功",
          data: data
        }
      } else {
        ctx.body = {
          code: 500,
          msg: "暂无数据",
          data: []
        }
      }
    }
  }

  //订单概述
  async ordergeneralize() {
    const { ctx } = this;
    const results = await this.app.mysql.select('dingai');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //评价管理
  async order() {
    const { ctx } = this;
    const results = await this.app.mysql.select('pinguan');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //删除
  async orderDel() {
    const { ctx } = this;
    const { id } = ctx.query
    const data = await this.app.mysql.delete('pinguan', {
      id: id,
    });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }

  //订单配送
  async orderdistribution() {
    const { ctx } = this;
    const results = await this.app.mysql.select('orderpeisong');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //搜搜
  async orderdistributionsou() {
    const { ctx } = this;
    const { name, sou } = ctx.query;
    console.log(name, "anme", sou, "志儒sou");
    if (sou === "全部") {
      const { ctx } = this;
      const results = await this.app.mysql.select('orderpeisong');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (name === "" || name) {
        if (name === "") {
          const { ctx } = this;
          const results = await this.app.mysql.select('orderpeisong');
          ctx.body = {
            code: 200,
            msg: "请求成功",
            data: results
          }
        } else {
          const sql = `SELECT * FROM orderpeisong where name like'%${name}%'`
          const data = await this.app.mysql.query(sql)
          if (data.length > 0) {
            ctx.body = {
              code: 200,
              msg: "搜索成功",
              data: data
            }
          } else {
            ctx.body = {
              code: 500,
              msg: "暂无数据",
            }
          }

        }
      } else if (sou) {
        const sql = `SELECT * FROM orderpeisong where orderState like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }

  }
  //删除
  async orderdistributionDel() {
    const { ctx } = this;
    const { id } = ctx.query
    console.log(id, "idd");
    const data = await this.app.mysql.delete('orderpeisong', {
      id: id,
    });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //==================团长============
  //团长管理
  async colonel() {
    const { ctx } = this;
    const results = await this.app.mysql.select('tuanguan');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }

  //团长管理模糊搜索
  async colonelsearch() {
    const { ctx } = this;
    const { name } = ctx.query;
    const sql = `SELECT * FROM tuanguan where name like'%${name}%'`
    const data = await this.app.mysql.query(sql)
    if (data.length > 0) {
      ctx.body = {
        code: 200,
        msg: "搜索成功",
        data: data
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "暂无数据",
      }
    }

  }
  //团长审核
  async colonelaudit() {
    const { ctx } = this;
    const results = await this.app.mysql.select('tuanshen');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //搜搜
  async colonelauditsou() {
    const { ctx } = this;
    const { name, sou } = ctx.query;
    console.log(name, "裴倩倩");
    if (sou === "请选择" || sou === "") {
      const results = await this.app.mysql.select('tuanshen');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (name === "" || name) {
        if (name === "") {
          const results = await this.app.mysql.select('tuanshen');
          ctx.body = {
            code: 200,
            msg: "请求成功",
            data: results
          }
        } else {
          const sql = `SELECT * FROM tuanshen where shenname like'%${name}%'`
          const data = await this.app.mysql.query(sql)
          if (data.length > 0) {
            ctx.body = {
              code: 200,
              msg: "搜索成功",
              data: data
            }
          } else {
            ctx.body = {
              code: 500,
              msg: "暂无数据",
            }
          }
        }
      } else {
        const sql = `SELECT * FROM tuanshen where lls like'%${sou}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      }
    }
  }

  //等级
  async colonelawait() {
    const { ctx } = this;
    const results = await this.app.mysql.select('tuanden');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //等级删除
  async colonelawaitDel() {
    const { ctx } = this;
    const { id } = ctx.query
    const data = await this.app.mysql.delete('tuanden', {
      id: id,
    });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }
  //路线
  async colonereude() {
    const { ctx } = this;
    const results = await this.app.mysql.select('luxian');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //编辑
  async colonereudebian() {
    const { ctx } = this; const { id, luxian, name, tel, city, jinwei, ren, lls } = ctx.query
    console.log(id, luxian, name, tel, city, jinwei, ren, lls, "世");
    const data = await this.app.mysql.update('luxian', { id: id, luxian: luxian, name: name, tel: tel, city: city, jinwei: jinwei, ren: ren, lls: lls });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "编辑成功",

      }
    } else {
      ctx.body = {
        code: 500,
        msg: "编辑失败",
      }
    }
  }
  //增加
  async colonereudeupdata() {
    const { ctx } = this; const { luxian, name, tel, city, jinwei, ren, lls } = ctx.query
    console.log(luxian, name, tel, city, jinwei, ren, lls, "b白");
    const data = await this.app.mysql.insert('luxian', { luxian: luxian, name: name, tel: tel, city: city, jinwei: "3.849776,18.986010", ren: ren, lls: lls, });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "增加成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "增加失败",
      }
    }
  }


  //路线删除
  async colonereudeDel() {
    const { ctx } = this;
    const { id } = ctx.query
    const data = await this.app.mysql.delete('luxian', {
      id: id,
    });
    if (data.affectedRows === 1) {
      ctx.body = {
        code: 200,
        msg: "删除成功",
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "删除失败",
      }
    }
  }

  //路线搜索
  async colonereudesou() {
    const { ctx } = this;
    const { name } = ctx.query;
    const sql = `SELECT * FROM luxian where name like'%${name}%'`
    const data = await this.app.mysql.query(sql)
    if (data.length > 0) {
      ctx.body = {
        code: 200,
        msg: "搜索成功",
        data: data
      }
    } else {
      ctx.body = {
        code: 500,
        msg: "暂无数据",
      }
    }

  }
  // async s() {
  //   const { ctx } = this;
  //   // const { id} = ctx.query;
  //   const sql = `UPDATE guige SET name=123  specification=456 property=123 WHERE id = 1`
  //   const data = await this.app.mysql.query(sql)
  //   ctx.body = {
  //     code: 200,
  //     msg: "请求成功",
  //     data: data
  //   }
  // }
  //佣金流水
  async colonermanry() {
    const { ctx } = this;
    const results = await this.app.mysql.select('yongjin');
    ctx.body = {
      code: 200,
      msg: "请求成功",
      data: results
    }
  }
  //佣金流水搜索
  async colonermanrysou() {
    const { ctx } = this;
    const { name, lls, danglls } = ctx.query;
    console.log(name, "names");

    if (lls === "全部") {
      const results = await this.app.mysql.select('yongjin');
      ctx.body = {
        code: 200,
        msg: "请求成功",
        data: results
      }
    } else {
      if (name === "" || name) {
        if (name === "") {

        }
        console.log(name, "456");
        const sql = `SELECT * FROM yongjin where name like'%${name}%'`
        const data = await this.app.mysql.query(sql)
        console.log(data.length > 0, "123");
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功name",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      } else if (lls) {
        const sql = `SELECT * FROM yongjin where lls like'%${lls}%'`
        const data = await this.app.mysql.query(sql)
        if (data.length > 0) {
          ctx.body = {
            code: 200,
            msg: "搜索成功jins",
            data: data
          }
        } else {
          ctx.body = {
            code: 500,
            msg: "暂无数据",
          }
        }
      } else if (danglls) {
        if (danglls === "所有订单") {
          const results = await this.app.mysql.select('yongjin');
          ctx.body = {
            code: 200,
            msg: "请求成功",
            data: results
          }
        } else {
          const sql = `SELECT * FROM yongjin where danglls like'%${danglls}%'`
          const data = await this.app.mysql.query(sql)
          if (data.length > 0) {
            ctx.body = {
              code: 200,
              msg: "搜索成功",
              data: data
            }
          } else {
            ctx.body = {
              code: 500,
              msg: "暂无数据",
            }
          }
        }
      }

    }


  }

}
module.exports = HomeController;




